home *** CD-ROM | disk | FTP | other *** search
Modula Implementation | 1997-04-23 | 26.2 KB | 735 lines | [TEXT/3PRM] |
- implementation module dialogInternal;
-
- import StdClass,StdInt, StdMisc, StdString, StdBool, StdChar,StdArray;
- import menus, windows, dialogs, structure, memory, controls, quickdraw;
- import Picture, dialogDef, ioState, windowDevice;
- from menuInternal import CheckItemTitle;
-
- ModelessDialogType :== 4; // The window type must be NoGrowDocProc = 4
- ModalDialogType :== 1; // The window type must be dBoxProc = 1
- EmptyDialogPtr :== -1;
- PopUpMenuID :== 235;
-
-
- :: NoticeRep *s :== (!NoticeHandle s (IOState s), !DialogPtr);
- :: Response *s
- = Final (ButtonFunction s (IOState s))
- | RadioBox (DialogFunction s (IOState s))
- | Void_new;
-
-
- DialogInternalError :: String String -> .x;
- DialogInternalError f error = Error f "dialogInternal" error;
-
-
- // Functions on DialogDef's and ItemLists.
-
- GetDialogDefId :: !(DialogDef s io) -> DialogId;
- GetDialogDefId (PropertyDialog id _ _ _ _ _) = id;
- GetDialogDefId (CommandDialog id _ _ _ _ ) = id;
-
-
- // Get a PopUpHandle from a list of PopUpHandles.
-
- GetPopUpHandle :: !DialogItemId ![PopUpHandle] -> PopUpHandle;
- GetPopUpHandle pid [handle=:(id,m) : rest]
- | pid == id = handle;
- = GetPopUpHandle pid rest;
- GetPopUpHandle pid []
- = DialogInternalError "GetPopUpHandle" ("Unknown item id: " +++ toString pid);
-
-
- // OpenAnyDialog opens a dialog.
-
- OpenAnyDialog :: !DialogMode !DialogPtr !(DialogDef s (IOState s)) !Toolbox
- -> (!DialogRep s (IOState s), !Toolbox);
- OpenAnyDialog mode ptr dDef tb
- = (dRep1, HiliteDialogItems dRep1 tb1);
- where {
- (dRep1,tb1) = CreateDialog ptr (DialogDefToDialogHandle mode dDef, EmptyDialogPtr) tb;
- };
-
-
- // DoNotice opens and handles the notice specified by the NoticeDef argument.
-
- DoNotice :: !NoticeDef !(IOState s) -> (!NoticeButtonId, !IOState s);
- DoNotice nDef ioState
- = DeactivateNotice (HandleNoticeEvents nRep tb1) outlineF ioState3;
- where {
- (cShape,ioState1) = IOStateGetGlobalCursor ioState;
- ioState2 = IOStateSetCursorShape cShape ioState1;
- (tb, ioState3) = IOStateGetToolbox ioState2;
- (nRep,outlineF,tb1) = CreateNotice (NoticeDefToNoticeHandle nDef,EmptyDialogPtr) tb;
- };
-
-
- /* HandleDialogEvent handles an event for a modal or a modeless dialog:
- Given the number of the clicked item it shows the effect of the click and
- returns the appropriate Response. */
-
- HandleDialogEvent :: !(DialogHandle s (IOState s)) !DialogPtr !Toolbox !Int
- -> (!DialogRep s (IOState s), !Response s, !Toolbox);
- HandleDialogEvent (DialogH id tt md rc ps items rs) ptr tb itemNr
- = ((DialogH id tt md rc ps items1 rs, ptr), resp, tb1);
- where {
- (items1, resp, tb1) = HandleDialogItemEvent items ptr tb 1 itemNr;
- };
-
- HandleDialogItemEvent :: ![DialogItem s (IOState s)] !DialogPtr !Toolbox !Int !Int
- -> (![DialogItem s (IOState s)], !Response s, !Toolbox);
- HandleDialogItemEvent items=:[button=:DialogButton id ps tt ss butfunc : rest] ptr tb i itemnr
- | i == itemnr = (items, Final butfunc, tb);
- = ([button : rest`], resp, tb1);
- where {
- (rest`, resp, tb1) = HandleDialogItemEvent rest ptr tb (inc i) itemnr;
- };
- HandleDialogItemEvent [CheckBoxes id p r boxes : rest] ptr tb i itemnr
- = ([CheckBoxes id p r boxes` : rest`], resp, tb1);
- where {
- (boxes`, rest`, resp, tb1) = HandleCheckBoxEvent boxes rest ptr tb i itemnr;
- };
- HandleDialogItemEvent [buts=:RadioButtons id p r pid buttons : rest] ptr tb i itemnr
- | itemnr >= iplusnrb = ([buts : rest`], resp1, tb1);
- = ([RadioButtons id p r pid` buttons : rest], resp2, tb2);
- where {
- (rest`,resp1,tb1) = HandleDialogItemEvent rest ptr tb iplusnrb itemnr;
- (pid` ,resp2,tb2) = HandleRadioButtonEvent pid buttons ptr tb i itemnr;
- iplusnrb = i + Length_new buttons;
- };
- HandleDialogItemEvent [item=:DialogPopUp id ps ab di bs : rest] ptr tb i itemnr
- = ([item : rest`], resp, tb1);
- where {
- (rest`, resp, tb1) = HandleDialogItemEvent rest ptr tb i itemnr;
- };
- HandleDialogItemEvent [item=:DialogIconButton id ps pd il ab bf : rest] ptr tb i itemnr
- = ([item : rest`], resp, tb1);
- where {
- (rest`, resp, tb1) = HandleDialogItemEvent rest ptr tb i itemnr;
- };
- HandleDialogItemEvent [item=:Control id ps pd ab cs cl cf df : rest] ptr tb i itemnr
- = ([item : rest`], resp, tb1);
- where {
- (rest`, resp, tb1) = HandleDialogItemEvent rest ptr tb i itemnr;
- };
- HandleDialogItemEvent [item : rest] ptr tb i itemnr
- = ([item : rest`], resp, tb1);
- where {
- (rest`, resp, tb1) = HandleDialogItemEvent rest ptr tb (inc i) itemnr;
- };
- HandleDialogItemEvent rest _ tb _ _ = (rest,Void_new, tb);
-
- HandleCheckBoxEvent :: ![CheckBoxDef s (IOState s)] ![DialogItem s (IOState s)] !DialogPtr !Toolbox !Int !Int
- -> (![CheckBoxDef s (IOState s)], ![DialogItem s (IOState s)], !Response s, !Toolbox);
- HandleCheckBoxEvent [box=:CheckBox id tt ss mark dfunc : rest] items ptr tb i itemnr
- | thisitem && Checked mark = ([box1 : rest ], items, RadioBox dfunc, SetCtlValue h 0 tb1);
- | thisitem = ([box1 : rest ], items, RadioBox dfunc, SetCtlValue h 1 tb1);
- = ([box : rest`], items`, resp, tb`);
- where {
- thisitem = i == itemnr;
- box1 = CheckBox id tt ss (MarkSwitch mark) dfunc;
- (it,h,rect,tb1) = GetDItem ptr i tb;
- (rest`,items`,resp,tb`) = HandleCheckBoxEvent rest items ptr tb (inc i) itemnr;
- };
- HandleCheckBoxEvent rest items ptr tb i itemnr
- = (rest, items`, resp, tb`);
- where {
- (items`, resp, tb`) = HandleDialogItemEvent items ptr tb i itemnr;
- };
-
- HandleRadioButtonEvent :: !Int ![RadioItemDef s (IOState s)] !DialogPtr !Toolbox !Int !Int
- -> (!Int, !Response s, !Toolbox);
- HandleRadioButtonEvent pid [but=:RadioItem id tt ss dfunc : rest] ptr tb i itemnr
- | found && idmatch = (id, Void_new, tb);
- | found = (id, RadioBox dfunc, SetCtlValue h 1 tb2 );
- | idmatch = (id`,resp, SetCtlValue h` 0 tb``);
- = (id`,resp, tb`);
- where {
- tb1 = UnpressRadioButton pid rest ptr tb (inc i);
- (_,h,_,tb2) = GetDItem ptr i tb1;
- (id`,resp,tb`) = HandleRadioButtonEvent pid rest ptr tb (inc i) itemnr;
- (_,h`,_,tb``) = GetDItem ptr i tb`;
- found = i == itemnr;
- idmatch = id == pid;
- };
- HandleRadioButtonEvent _ _ _ _ _ _
- = DialogInternalError "HandleRadioButtonEvent" "Event is no radio button event";
-
- /* UnpressRadioButton unpresses the radio button with the indicated id. The fourth parameter
- is the item number of the first radio button in the list. */
-
- UnpressRadioButton :: !DialogItemId ![RadioItemDef s (IOState s)] !DialogPtr !Toolbox !Int -> Toolbox;
- UnpressRadioButton pid [RadioItem id tt ss df : rest] ptr tb i
- | id == pid = SetCtlValue h 0 tb1;
- = UnpressRadioButton pid rest ptr tb (inc i);
- where {
- (it,h,rect,tb1) = GetDItem ptr i tb;
- };
- UnpressRadioButton _ _ _ tb _ = tb;
-
-
- // Notice event handling.
-
- HandleNoticeEvents :: !(NoticeRep s) !Toolbox -> (!NoticeButtonId, !NoticeRep s, !Toolbox);
- HandleNoticeEvents nRep=:(_,ptr) tb
- = HandleNoticeEvent nRep itemNr tb1;
- where {
- (itemNr, tb1) = ModalDialog 0 ptr tb;
- };
-
- HandleNoticeEvent :: !(NoticeRep s) !Int !Toolbox -> (!NoticeButtonId, !NoticeRep s, !Toolbox);
- HandleNoticeEvent nRep=:(notice,_) nr tb
- | nr > 0 = (FindNoticeButtonId nr notice, nRep, tb);
- = HandleNoticeEvents nRep tb;
-
- FindNoticeButtonId :: !Int !(NoticeHandle s (IOState s)) -> NoticeButtonId;
- FindNoticeButtonId nr (NoticeH _ items) = FindButtonIdInItemList nr items;
-
- FindButtonIdInItemList :: !Int ![DialogItem s (IOState s)] -> NoticeButtonId;
- FindButtonIdInItemList 1 [DialogButton id _ _ _ _ : _] = id;
- FindButtonIdInItemList 1 _ = -1;
- FindButtonIdInItemList n [_ : items] = FindButtonIdInItemList (dec n) items;
-
-
- // Create and activate a dialog.
-
- CreateDialog :: !DialogPtr !(DialogRep s (IOState s)) !Toolbox -> (!DialogRep s (IOState s), !Toolbox);
- CreateDialog ptr (dH=:DialogH id tt md rc ps items rs, EmptyDialogPtr) tb
- = ((DialogH id tt md rc popUpHs items rs, dPtr), tb2);
- where {
- (dPtr, tb1) = MakeDialog ptr dH tb;
- (popUpHs,tb2) = CreatePopUpHandles DialogFont items tb1;
- };
- CreateDialog _ _ _
- = DialogInternalError "CreateDialog" "Cannot create the same dialog twice";
-
- CreatePopUpHandles :: !Font ![DialogItem s (IOState s)] !Toolbox -> (![PopUpHandle], !Toolbox);
- CreatePopUpHandles dfont [DialogPopUp id (ItemBox l t w h) ab di buts : rest] tb
- = ([(id,menuH) : popUpHs], tb3);
- where {
- (menuH,tb1) = NewMenu PopUpMenuID "" tb;
- tb2 = AppendPopUpButtons di buts 1 menuH tb1;
- (popUpHs, tb3) = CreatePopUpHandles dfont rest tb2;
- };
- CreatePopUpHandles dfont [_ : rest] tb = CreatePopUpHandles dfont rest tb;
- CreatePopUpHandles _ _ tb = ([],tb);
-
- AppendPopUpButtons :: !DialogItemId ![RadioItemDef s (IOState s)] !Int !MacMenuHandle !Toolbox -> Toolbox;
- AppendPopUpButtons pid [RadioItem id title abty df : rest] itemnr menuH tb
- = AppendPopUpButtons pid rest (inc itemnr) menuH tb2;
- where {
- tb1 = AppendMenu menuH (MacMetaChars (pid == id) abty) tb;
- tb2 = SetItem menuH itemnr (CheckItemTitle title) tb1;
-
- };
- AppendPopUpButtons _ _ _ _ tb = tb;
-
- MacMetaChars :: !Bool !SelectState -> String;
- MacMetaChars mark abty
- | mark && able = title +++ check;
- | mark = title +++ disable +++ check;
- | able = title;
- = title +++ disable;
- where {
- able = Enabled abty;
- title = " ";
- disable = "(";
- check = "!" +++ toString (toChar 18);
- };
-
- MakeDialog :: !DialogPtr !(DialogHandle s (IOState s)) !Toolbox -> (!DialogPtr, !Toolbox);
- MakeDialog behind (DialogH id title Modal rect popups items rest) tb
- | hasColor = NewCDialog 0 rect title True ModalDialogType behind False 0 items1 tb2;
- = NewDialog 0 rect title True ModalDialogType behind False 0 items1 tb2;
- where {
- (hasColor, tb1) = HasColorQD tb;
- (items1, tb2) = CreateDialogItems items tb1;
- };
- MakeDialog behind (DialogH id title modeless rect popups items rest) tb
- | hasColor = NewCDialog 0 rect title True ModelessDialogType behind True 0 items1 tb2;
- = NewDialog 0 rect title True ModelessDialogType behind True 0 items1 tb2;
- where {
- (hasColor, tb1) = HasColorQD tb;
- (items1, tb2) = CreateDialogItems items tb1;
- };
-
-
- // Create and activate a notice.
-
- CreateNotice :: !(NoticeRep s) !Toolbox -> (!NoticeRep s, !ProcPtr, !Toolbox);
- CreateNotice (notice=:(NoticeH rect items),EmptyDialogPtr) tb
- = ((notice, nPtr), outlineF, tb2);
- where {
- (items1,outlineF,tb1) = CreateNoticeItems items tb;
- (nPtr, tb2) = NewDialog 0 rect "" True ModalDialogType (-1) False 0 items1 tb1;
- };
- CreateNotice _ _
- = DialogInternalError "CreateNotice" "Cannot activate the same notice twice";
-
-
- // Activate/Deactivate and dispose a dialog.
-
- ActivateDialog :: !(DialogHandles s) !Toolbox -> Toolbox;
- ActivateDialog [(_,ptr) :_] tb = SelectWindow ptr tb;
-
- DeactivateDialog :: !(DialogRep s (IOState s)) !(IOState s) -> IOState s;
- DeactivateDialog (DialogH _ _ _ _ popUpHs _ _, ptr) ioState
- = IOStateSetToolbox (DisposDialog ptr (DisposePopUpMenus popUpHs tb)) ioState1;
- where {
- (tb, ioState1) = IOStateGetToolbox ioState;
- };
-
- DisposePopUpMenus :: ![PopUpHandle] !Toolbox -> !Toolbox;
- DisposePopUpMenus [(_,menuH) : rest] tb = DisposePopUpMenus rest (DisposeMenu menuH tb);
- DisposePopUpMenus _ tb = tb;
-
-
- // Deactivate and dispose a notice.
-
- DeactivateNotice :: !(!NoticeButtonId, !NoticeRep s, !Toolbox) !ProcPtr !(IOState s)
- -> (!NoticeButtonId, !IOState s);
- DeactivateNotice (id,(_,ptr),tb) outlineF ioState
- = (id, IOStateSetToolbox (DisposDialog ptr (DisposeRoutineDescriptor outlineF tb)) ioState);
-
-
- /* After the creation and filling of the dialog the inactive items must be hilited,
- the marked check boxes must be marked and the pressed radio button must be pressed. */
-
- HiliteDialogItems :: !(DialogRep s (IOState s)) !Toolbox -> Toolbox;
- HiliteDialogItems (DialogH _ _ _ _ _ items _, ptr) tb = HiliteItems True ptr items tb 1;
-
- HiliteItems :: !Bool !DialogPtr ![DialogItem s (IOState s)] !Toolbox !Int -> Toolbox;
- HiliteItems b ptr [CheckBoxes id ps rc boxes : items] tb nr
- = HiliteCheckBoxes ptr boxes items b tb nr;
- HiliteItems b ptr [RadioButtons id ps rc pid buttons : items] tb nr
- = HiliteRadioButtons ptr buttons items b pid tb nr;
- HiliteItems b ptr [DialogButton id t s ability bf : items] tb nr
- | Enabled ability = tb1;
- = Hilite ptr nr tb1;
- where {
- tb1 = HiliteItems b ptr items tb (inc nr);
- };
- HiliteItems notyet ptr [EditText id ps wd nl txt : items] tb nr
- | notyet && txt <> "" = SelIText ptr nr 0 32767 tb1;
- = tb1;
- where {
- tb1 = HiliteItems False ptr items tb (inc nr);
- };
- HiliteItems b ptr [DialogPopUp id ps ab di bs : items] tb nr
- = HiliteItems b ptr items tb nr;
- HiliteItems b ptr [DialogIconButton id ps pd il ab bf : items] tb nr
- = HiliteItems b ptr items tb nr;
- HiliteItems b ptr [Control id ps pd ab cs cl cf df : items] tb nr
- = HiliteItems b ptr items tb nr;
- HiliteItems b ptr [_ : items] tb nr
- = HiliteItems b ptr items tb (inc nr);
- HiliteItems _ _ _ tb _ = tb;
-
- HiliteRadioButtons :: !DialogPtr ![RadioItemDef s (IOState s)] ![DialogItem s (IOState s)]
- !Bool !DialogId !Toolbox !Int -> Toolbox;
- HiliteRadioButtons ptr [RadioItem id tt Able df : buttons] items b pid tb nr
- | id == pid = SetCtlValue h 1 tb2;
- = tb1;
- where {
- tb1 = HiliteRadioButtons ptr buttons items b pid tb (inc nr);
- (_,h,_,tb2) = GetDItem ptr nr tb1;
- };
- HiliteRadioButtons ptr [RadioItem id tt unable df : buttons] items b pid tb nr
- | id == pid = HiliteControl h 255 (SetCtlValue h 1 tb2);
- = Hilite ptr nr tb1;
- where {
- tb1 = HiliteRadioButtons ptr buttons items b pid tb (inc nr);
- (_,h,_,tb2) = GetDItem ptr nr tb1;
- };
- HiliteRadioButtons ptr _ items b _ tb nr = HiliteItems b ptr items tb nr;
-
- HiliteCheckBoxes :: !DialogPtr ![CheckBoxDef s (IOState s)] ![DialogItem s (IOState s)]
- !Bool !Toolbox !Int -> Toolbox;
- HiliteCheckBoxes ptr [CheckBox id tt Able mark df : boxes] items b tb nr
- | Checked mark = SetCtlValue h 1 tb2;
- = tb1;
- where {
- tb1 = HiliteCheckBoxes ptr boxes items b tb (inc nr);
- (_,h,_,tb2) = GetDItem ptr nr tb1;
- };
- HiliteCheckBoxes ptr [CheckBox id tt unable mark df : boxes] items b tb nr
- | Checked mark = HiliteControl h 255 (SetCtlValue h 1 tb2);
- = Hilite ptr nr tb1;
- where {
- tb1 = HiliteCheckBoxes ptr boxes items b tb (inc nr);
- (_,h,_,tb2) = GetDItem ptr nr tb1;
- };
- HiliteCheckBoxes ptr _ items b tb nr = HiliteItems b ptr items tb nr;
-
- Hilite :: !DialogPtr !Int !Toolbox -> Toolbox;
- Hilite dPtr itemNr tb
- = HiliteControl h 255 tb1;
- where {
- (_,h,_,tb1) = GetDItem dPtr itemNr tb;
- };
-
- Unhilite :: !DialogPtr !Int !Toolbox -> Toolbox;
- Unhilite dPtr itemNr tb
- = HiliteControl h 0 tb1;
- where {
- (_,h,_,tb1) = GetDItem dPtr itemNr tb;
- };
-
-
- // Draw a DialogPopUp, an IconButton or a Control in a dialog.
-
- DrawDefButtonOutline :: !ItemPos !DialogPtr !Toolbox -> Toolbox;
- DrawDefButtonOutline (ItemBox l t w h) dPtr tb
- = tb6;
- where {
- (port, tb1) = QGetPort tb;
- tb2 = QSetPort dPtr tb1;
- tb3 = QPenSize 3 3 tb2;
- tb4 = QFrameRoundRect rect 16 16 tb3;
- tb5 = QPenSize 1 1 tb4;
- tb6 = QSetPort port tb5;
- rect = (l - 4,t - 4, l + w + 4, t + h + 4);
- };
-
- RedrawPopUp :: !ItemPos !SelectState !String !DialogPtr !Toolbox -> Toolbox;
- RedrawPopUp (ItemBox l t w h) select item dPtr tb
- = tb5;
- where {
- (port, tb1) = QGetPort tb;
- tb2 = QSetPort dPtr tb1;
- tb3 = QEraseRect (l,t,inc (l + w),inc (t + h)) tb2;
- tb4 = QDrawPopUp (l,t,w,h) able item tb3;
- tb5 = QSetPort port tb4;
- able = Enabled select;
- };
-
- QDrawPopUp :: !Rect !Bool !String !Toolbox -> Toolbox;
- QDrawPopUp (l,t,w,h) able item tb
- = tb7;
- where {
- tb1 = QDrawArrow able r t tb;
- tb2 = QMoveTo (l + 4) base tb1;
- tb3 = QDrawString item tb2;
- tb4 = QFrameRect (l,t,r1,b1) tb3;
- tb5 = QMoveTo r1 (t + 2) tb4;
- tb6 = QLineTo r1 b1 tb5;
- tb7 = QLineTo (l + 2) b1 tb6;
- r1 = inc r;
- b1 = inc b;
- r = l + w;
- b = t + h;
- base= t + BaseOfs;
- };
-
- RedrawPopUpItemText :: !ItemPos !String !DialogPtr !Toolbox -> Toolbox;
- RedrawPopUpItemText (ItemBox l t w h) item dPtr tb
- = tb8;
- where {
- (port, tb1) = QGetPort tb;
- tb2 = QSetPort dPtr tb1;
- tb3 = QEraseRect (inc l,inc t,r - 17,b) tb2;
- tb4 = QMoveTo (l + 4) (t + BaseOfs) tb3;
- tb5 = QTextMode SrcOr tb4;
- tb6 = QDrawString item tb5;
- tb7 = QTextMode SrcCopy tb6;
- tb8 = QSetPort port tb7;
- r = l + w;
- b = t + h;
- };
-
- DrawPopUpAbility :: !ItemPos !SelectState !DialogPtr !Toolbox -> Toolbox;
- DrawPopUpAbility (ItemBox l t w h) select dPtr tb
- = tb4;
- where {
- (port, tb1) = QGetPort tb;
- tb2 = QSetPort dPtr tb1;
- tb3 = QDrawArrow (Enabled select) (l + w) t tb2;
- tb4 = QSetPort port tb3;
- };
-
- QDrawArrow :: !Bool !Int !Int !Toolbox -> Toolbox;
- QDrawArrow able x y tb
- | able = enarrow;
- = QPenPat Black disarrow;
- where {
- enarrow = MakeMacPicture (FillPolygon arrow (MakePicture tb));
- disarrow = MakeMacPicture (FillPolygon arrow dpict);
- dpict = MakePicture (QPenPat Gray tb);
- arrow = ((x - 16,y + 6), [(12,0), (-6,6)]);
- };
-
- DrawIconOrControl :: !ItemPos !Rectangle ![DrawFunction] !DialogPtr !Toolbox -> Toolbox;
- DrawIconOrControl (ItemBox bl bt w h) ((rl,rt),(r,b)) look dPtr tb
- = tb11;
- where {
- (port,tb1) = QGetPort tb;
- tb2 = QSetPort dPtr tb1;
- (rgn, tb3) = QNewRgn tb2;
- (rgn1,tb4) = QGetClip rgn tb3;
- tb5 = QSetOrigin (rl - bl) (rt - bt) tb4;
- tb6 = QClipRect (rl,rt,r,b) tb5;
- tb7 = DrawTheLook look tb6;
- tb8 = QSetOrigin 0 0 tb7;
- tb9 = QSetClip rgn1 tb8;
- tb10 = QSetPort port tb9;
- tb11 = QDisposeRgn rgn1 tb10;
- };
-
- RedrawIconOrControl :: !ItemPos !Rectangle ![DrawFunction] !DialogPtr !Toolbox -> Toolbox;
- RedrawIconOrControl (ItemBox bl bt w h) ((rl,rt),(r,b)) look dPtr tb
- = tb12;
- where {
- (port, tb1) = QGetPort tb;
- tb2 = QSetPort dPtr tb1;
- (rgn, tb3) = QNewRgn tb2;
- (rgn1, tb4) = QGetClip rgn tb3;
- tb5 = QSetOrigin (rl - bl) (rt - bt) tb4;
- tb6 = QClipRect rect tb5;
- tb7 = QEraseRect rect tb6;
- tb8 = DrawTheLook look tb7;
- tb9 = QSetOrigin 0 0 tb8;
- tb10 = QSetClip rgn1 tb9;
- tb11 = QSetPort port tb10;
- tb12 = QDisposeRgn rgn1 tb11;
- rect = (rl,rt,r,b);
- };
-
- DrawTheLook :: ![DrawFunction] !Toolbox -> Toolbox;
- DrawTheLook look tb
- = tb4;
- where {
- tb1 = MakeMacPicture (ApplyDrawFunctions look (MakePicture tb));
- tb2 = QTextFont 0 tb1;
- tb3 = QTextFace 0 tb2;
- tb4 = QTextSize 0 tb3;
- };
-
- ApplyDrawFunctions :: ![DrawFunction] !Picture -> Picture;
- ApplyDrawFunctions [drawF : drawFs] picture = ApplyDrawFunctions drawFs (drawF picture);
- ApplyDrawFunctions drawFs picture
- = picture3;
- where {
- picture1 = SetBackColour WhiteColour picture;
- picture2 = SetPenColour BlackColour picture1;
- picture3 = SetPenNormal picture2;
- };
-
-
- // Create the items of a dialog.
-
- CreateDialogItems :: ![DialogItem s (IOState s)] !Toolbox -> (!Handle,!Toolbox);
- CreateDialogItems items tb
- = (h1, tb4);
- where {
- (h1, ptr1) = s1;
- (s1, tb4) = FillDialogItems items s tb3;
- (s, tb3) = Append_word (h,ptr) c tb2;
- (ptr,tb2) = DereferenceHandle h tb1;
- (h, tb1) = AllocateHandle size tb;
- (c, size) = DialogItemsSize items;
- };
-
- CreateNoticeItems :: ![DialogItem s (IOState s)] !Toolbox -> (!Handle, !ProcPtr, !Toolbox);
- CreateNoticeItems items tb
- = (h1, outlineF, tb5);
- where {
- (h1, ptr1) = s2;
- (s2, tb5) = AppendUserItem rect outlineF (s1, tb4);
- outlineF = OutlineButtonFunction;
- (s1, tb4) = FillDialogItems items s tb3;
- (s, tb3) = Append_word (h,ptr) c tb2;
- (ptr,tb2) = DereferenceHandle h tb1;
- (h, tb1) = AllocateHandle size tb;
- (c, size) = NoticeItemsSize items;
- rect = GetDefaultButtonRect items;
- };
-
- GetDefaultButtonRect :: ![DialogItem s (IOState s)] -> Rect;
- GetDefaultButtonRect [DialogButton _ (ItemBox l t w h) _ _ _ : _] = (l,t, l+w,t+h);
- GetDefaultButtonRect _
- = DialogInternalError "GetDefaultButtonRect" "No default button found in notice";
-
-
- /* Calculate the heap-size occupied by the dialog items. In a notice extra room must be
- reserved for the outline of the default button (a user item). */
-
- DialogItemsSize :: ![DialogItem s (IOState s)] -> (!Int,!Int);
- DialogItemsSize items = CalcItemsSize items (-1,2);
-
- NoticeItemsSize :: ![DialogItem s (IOState s)] -> (!Int,!Int);
- NoticeItemsSize items = CalcItemsSize items (0,16);
-
- CalcItemsSize :: ![DialogItem s (IOState s)] (!Int,!Int) -> (!Int,!Int);
- CalcItemsSize items cs
- = cs`;
- where {
- (items`, cs`) = StateMap CalcItemSize items cs;
- };
-
- CalcItemSize :: !(DialogItem s (IOState s)) !(!Int,!Int) -> (DialogItem s (IOState s), !(!Int,!Int));
- CalcItemSize item=:(DialogButton i l title a f) (c,s)
- = (item, (inc c, Align (size title + (s + 14))));
- CalcItemSize item=:(StaticText i l text) (c,s)
- = (item, (inc c, Align (size text + (s + 14))));
- CalcItemSize item=:(DynamicText i l w text) (c,s)
- = (item, (inc c, Align (size text + (s + 14))));
- CalcItemSize item=:(EditText i l w n text) (c,s)
- = (item, (inc c, Align (size text + (s + 14))));
- CalcItemSize item=:(CheckBoxes i l r boxes) (c,s)
- = (item, (c + nrb, s + size));
- where {
- (nrb,size) = CalcCheckBoxesSize boxes (0,0);
- };
- CalcItemSize item=:(RadioButtons i l r d buttons) (c,s)
- = (item, (c + nrb, s + size));
- where {
- (nrb,size) = CalcRadioButtonsSize buttons (0,0);
- };
- CalcItemSize item cs = (item, cs);
-
- CalcCheckBoxesSize :: ![CheckBoxDef s (IOState s)] (!Int,!Int) -> (!Int,!Int);
- CalcCheckBoxesSize [CheckBox i ttl a m f : boxes] (c,s)
- = CalcCheckBoxesSize boxes (inc c, Align (size ttl) + (s + 14));
- CalcCheckBoxesSize [] s = s;
-
- CalcRadioButtonsSize :: ![RadioItemDef s (IOState s)] (!Int,!Int) -> (!Int,!Int);
- CalcRadioButtonsSize [RadioItem i ttl a f : buttons] (c,s)
- = CalcRadioButtonsSize buttons (inc c, Align (size ttl) + (s + 14));
- CalcRadioButtonsSize [] s = s;
-
-
- // Place the items in the item list in the dialog.
-
- FillDialogItems :: ![DialogItem s (IOState s)] !Structure !Toolbox -> (!Structure,!Toolbox);
- FillDialogItems items struct tb
- = s;
- where {
- (items1, s) = StateMap FillDlogItem items (struct, tb);
- };
-
- FillDlogItem :: !(DialogItem s (IOState s)) !(!Structure, !Toolbox)
- -> (DialogItem s (IOState s), !(!Structure, !Toolbox));
- FillDlogItem item=:(DialogButton i (ItemBox l t w h) title a f) s
- = (item, AppendButton (l,t,l + w,t + h) title s);
- FillDlogItem item=:(StaticText i (ItemBox l t w h) text) s
- = (item, AppendStaticText (l,t,l + w,t + h) text s);
- FillDlogItem item=:(DynamicText i (ItemBox l t w h) m text) s
- = (item, AppendStaticText (l,t,l + w,t + h) text s);
- FillDlogItem item=:(EditText i (ItemBox l t w h) m n text) s
- = (item, AppendEditText (l,t,l + w,t + h) text s);
- FillDlogItem item=:(CheckBoxes i (ItemBox l t w h) (Rows nr) boxes) s
- = (item, FillRowCheckBoxes 1 nr l t t w h boxes s);
- FillDlogItem item=:(CheckBoxes i (ItemBox l t w h) (Columns nr) boxes) s
- = (item, FillColumnCheckBoxes 1 nr l l t w h boxes s);
- FillDlogItem item=:(RadioButtons i (ItemBox l t w h) (Rows nr) d buttons) s
- = (item, FillRowRadioButtons 1 nr l t t w h buttons s);
- FillDlogItem item=:(RadioButtons i (ItemBox l t w h) (Columns nr) d buttons) s
- = (item, FillColumnRadioButtons 1 nr l l t w h buttons s);
- FillDlogItem item s = (item, s);
-
- FillRowCheckBoxes :: !Int !Int !Int !Int !Int !Int !Int
- ![CheckBoxDef s (IOState s)] !(!Structure, !Toolbox) -> (!Structure, !Toolbox);
- FillRowCheckBoxes i nr l t tt w h boxes=:[CheckBox id title a m f : rest] s
- | i > nr = FillRowCheckBoxes 1 nr (l + w) tt tt w h boxes s;
- = FillRowCheckBoxes (inc i) nr l b tt w h rest (AppendCheckBox (l,t, l+w,b) title s);
- where {
- b = t+h;
- };
- FillRowCheckBoxes _ _ _ _ _ _ _ _ s = s;
-
- FillColumnCheckBoxes :: !Int !Int !Int !Int !Int !Int !Int
- ![CheckBoxDef s (IOState s)] !(!Structure, !Toolbox) -> (!Structure, !Toolbox);
- FillColumnCheckBoxes i nr l ll t w h boxes=:[CheckBox id title a m f : rest] s
- | i > nr = FillColumnCheckBoxes 1 nr ll ll (t+h) w h boxes s;
- = FillColumnCheckBoxes (inc i) nr r ll t w h rest (AppendCheckBox (l,t,r,t+h) title s);
- where {
- r = l+w;
- };
- FillColumnCheckBoxes _ _ _ _ _ _ _ _ s = s;
-
- FillRowRadioButtons :: !Int !Int !Int !Int !Int !Int !Int
- ![RadioItemDef s (IOState s)] !(!Structure, !Toolbox) -> (!Structure, !Toolbox);
- FillRowRadioButtons i nr l t tt w h radios=:[RadioItem id title a f : rest] s
- | i > nr = FillRowRadioButtons 1 nr (l+w) tt tt w h radios s;
- = FillRowRadioButtons (inc i) nr l b tt w h rest (AppendRadioButton (l,t, l+w,b) title s);
- where {
- b = t+h;
- };
- FillRowRadioButtons _ _ _ _ _ _ _ _ s = s;
-
- FillColumnRadioButtons :: !Int !Int !Int !Int !Int !Int !Int
- ![RadioItemDef s (IOState s)] !(!Structure, !Toolbox) -> (!Structure, !Toolbox);
- FillColumnRadioButtons i nr l ll t w h radios=:[RadioItem id title a f : rest] s
- | i > nr = FillColumnRadioButtons 1 nr ll ll (t+h) w h radios s;
- = FillColumnRadioButtons (inc i) nr r ll t w h rest (AppendRadioButton (l,t,r,t+h) title s);
- where {
- r = l+w;
- };
- FillColumnRadioButtons _ _ _ _ _ _ _ _ s = s;
-
- AppendButton :: !Rect !String !(!Structure, !Toolbox) -> (!Structure, !Toolbox);
- AppendButton rect name (struct, tb)
- = Append_string_and_align struct2 name tb2;
- where {
- (struct1, tb1) = Append_zero_and_rect struct rect tb;
- (struct2, tb2) = Append_byte struct1 4 tb1;
- };
-
- AppendStaticText :: !Rect !String !(!Structure, !Toolbox) -> (!Structure, !Toolbox);
- AppendStaticText rect name (struct, tb)
- = Append_string_and_align struct2 name tb2;
- where {
- (struct1, tb1) = Append_zero_and_rect struct rect tb;
- (struct2, tb2) = Append_byte struct1 136 tb1;
- };
-
- AppendEditText :: !Rect !String !(!Structure, !Toolbox) -> (!Structure, !Toolbox);
- AppendEditText rect name (struct, tb)
- = Append_string_and_align struct2 name tb2;
- where {
- (struct1, tb1) = Append_zero_and_rect struct rect tb;
- (struct2, tb2) = Append_byte struct1 144 tb1;
- };
-
- AppendCheckBox :: !Rect !String !(!Structure, !Toolbox) -> (!Structure, !Toolbox);
- AppendCheckBox rect name (struct, tb)
- = Append_string_and_align struct2 name tb2;
- where {
- (struct1, tb1) = Append_zero_and_rect struct rect tb;
- (struct2, tb2) = Append_byte struct1 5 tb1;
- };
-
- AppendRadioButton :: !Rect !String !(!Structure, !Toolbox) -> (!Structure, !Toolbox);
- AppendRadioButton rect name (struct, tb)
- = Append_string_and_align struct2 name tb2;
- where {
- (struct1, tb1) = Append_zero_and_rect struct rect tb;
- (struct2, tb2) = Append_byte struct1 6 tb1;
- };
-
- AppendUserItem :: !Rect !ProcPtr !(!Structure, !Toolbox) -> (!Structure, !Toolbox);
- AppendUserItem (l,t,r,b) procPtr (struct, tb)
- = (struct7, tb7);
- where {
- (struct1, tb1) = Append_long struct procPtr tb;
- (struct2, tb2) = Append_word struct1 t tb1;
- (struct3, tb3) = Append_word struct2 l tb2;
- (struct4, tb4) = Append_word struct3 b tb3;
- (struct5, tb5) = Append_word struct4 r tb4;
- (struct6, tb6) = Append_byte struct5 128 tb5;
- (struct7, tb7) = Append_byte struct6 0 tb6;
- };
-
-
- /* Miscellaneous functions. */
-
- AllocateHandle :: !Int !Toolbox -> (!Handle, !Toolbox);
- AllocateHandle size tb
- | r <> 0 = DialogInternalError "AllocateHandle" "Out of memory";
- = (h, tb1);
- where {
- (h,r,tb1) = NewHandle size tb;
- };
-
- Align :: !Int -> Int;
- Align n = inc n bitand (-2);
-